# -*- coding:UTF-8 -*-
from cmdb.models import MerchantInfo

def merchant_info(start,end):
    count=MerchantInfo.objects.count()
    sRes = MerchantInfo.objects.order_by('-id')[start:end]
    return {'count':count,'merchant_info_list':sRes}

#获取所有商家信息
def get_merchant_infos():
    merRes = MerchantInfo.objects.all().values('id','factory_name')
    return merRes

#获取单条商家信息
def get_merchant_info(id):
    mRes = MerchantInfo.objects.get(id=id)
    return mRes

def add_merchant_info(factory_name, contacts, contact_way, comment, operator):
    mInfo = MerchantInfo(factory_name=factory_name, contacts=contacts, contact_way=contact_way,
                         comment=comment,operator=operator)
    mInfo.save()

def edit_merchant_info(id, factory_name, contacts, contact_way, comment, operator):
    mInfo = MerchantInfo.objects.get(id=id)
    mInfo.factory_name = factory_name
    mInfo.contacts = contacts
    mInfo.contact_way = contact_way
    mInfo.comment = comment
    mInfo.operator = operator
    mInfo.save()

def del_merchant_info(id):
    MerchantInfo.objects.get(id=id).delete()